﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace WFBASE
{
    public class WFFILE
    {
        /// <summary>
        /// 取得文件的内容
        /// </summary>
        /// <param name="fileName">文件绝对位置,like: d:\abc\cc.txt</param>
        /// <returns></returns>
        public static string LoadFileContent(string filePath, out string fileContent)
        {
            fileContent = "";
            try
            {
                StreamReader sr = new StreamReader(filePath, Encoding.Default);
                fileContent = sr.ReadToEnd();
                sr.Close();
                sr.Dispose();
                sr = null;
                return "Y";
            }
            catch (Exception ex)
            {
                WFException.WriteLog("WFFILE.LoadFileContent", "读取文件内容时发生错误[" + filePath + "]", ex.ToString());
                return ex.Message;
            }
        }

        //写入文件内容
        public static string WriteFileContent(string filePath, string fileContent, bool append)
        {
            try
            {
                StreamWriter sw = new StreamWriter(filePath, append, Encoding.Default);
                sw.Write(fileContent);
                sw.WriteLine("");
                sw.Flush();
                sw.Close();
                sw.Dispose();
                return "Y";
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }
    }
}
